using UnityEngine;
using QFramework;

namespace Survivor
{
	public partial class Bomb : ViewController
	{
		void Start()
		{
			CollectedBox.OnTriggerEnter2DEvent(BeCollect).UnRegisterWhenGameObjectDestroyed(gameObject);
		}

		void BeCollect(Collider2D co)
		{
			if (co.GetComponent<CollectableArea>())
			{
				foreach (var enemyObj in GameObject.FindGameObjectsWithTag("Enemy"))
				{
					var enemy = enemyObj.GetComponent<Enemy>();
					if (enemy && enemy.isActiveAndEnabled)
					{
						enemy.Hurt(enemy.hp);
					}
				}

				AudioKit.PlaySound("Bomb");
				this.DestroyGameObjGracefully();
			}
		}
	}
}
